<?php
// +----------------------------------------------------------------------
// | 奇乐中介担保交易系统 免费版 2019
// +----------------------------------------------------------------------
// | 官方网址：http://www.qilecms.com   
// +----------------------------------------------------------------------
// | 产品文档：http://www.qilecms.com/doc
// +----------------------------------------------------------------------
// | 开发作者: 奇乐CMS
// +----------------------------------------------------------------------
// | 版权说明：这不是一个自由软件！本产品仅限个人使用，但请务必保留底部版权，以免产生不必要的纠纷,
// | 您只能在不用于商业目的的前提下对程序代码进行修改和使用，
// | 任何企业和个人不允许对程序代码以任何形式任何目的再发布。
// +----------------------------------------------------------------------
namespace app\admin\controller;
use think\controller;
use think\Db;
class CertificationBank extends Base
{
	public function index(){
     $alias = 'a';        //需要别名时写别名，不需要的时候留空 
      $defaultWhere = '';  //默认where
      $defaultOrder = 'a.create_time desc';  //默认排序
    //接收搜索表单数据
      $SearchFormData = $this->getSearchFormData($defaultWhere,$defaultOrder);
      $where = $SearchFormData['where'];
      $order = $SearchFormData['order'];
      $pageNum = $SearchFormData['pageNum'];
// 关键词筛选  格式：字段名称加显示名称
     $keywords  = ['id'=>'认证ID','username'=>'用户名','bank'=>'开户银行','bank_branch'=>'开户网点','bank_account'=>'收款账号','bank_realname'=>'收款户名'];
//组建关键词数据
     $keywordsData  =[
                  [
                  'field'   =>'id', //字段名
                  'name'    =>'认证ID', //文本显示名称
                  'alias'   => $alias,  //字段对应的别名
                  ],
                  [
                  'field'   =>'username',
                  'name'    =>'用户名',
                  'alias'   => 'b',
                  ],
                  [
                  'field'   =>'bank',
                  'name'    =>'开户银行',
                  'alias'   => $alias,$alias,
                  ],
                  [
                  'field'   =>'bank_branch',
                  'name'    =>'开户网点',
                  'alias'   => $alias,
                  ],
                  [
                  'field'   =>'bank_account',
                  'name'    =>'收款账号',
                  'alias'   => $alias,
                  ],
     ];
//组建日期筛选   
       $dateData = [
                  [
                  'title'        =>'申请时间',  //标签显示名称
                  'field'        =>'create_time', //筛选字段
                  'start_name'   =>'开始时间', //开始时间
                  'end_name'     =>'结束时间', //结束时间
                  'alias'        => $alias,  //字段别名
                  ],

              ];
//单个字段筛选
    $customSingleField =[
                            [
                             'name'=>'认证状态',
                             'field' => 'status', 
                             'data'  => [ 0 =>'待审核',1=>'成功',2=>'失败'],
                             'alias'=>$alias,
                            ]
                       ]; 
// 组件字段组筛选
    $groupData = [];
     $orderData   = [];  

     $this->assign('keywordsData',$keywordsData);
     $this->assign('customSingleField',$customSingleField);
     $this->assign('groupData',$groupData);
     $this->assign('dateData',$dateData);
     $this->assign('orderData',$orderData);


     $list = DB::name('CertificationBank')
     ->field("a.id,a.bank_type,a.bank,a.bank_branch,a.bank_realname,a.bank_account,a.status,a.create_time,b.username")
     ->alias('a')
     ->join("user b","a.uid = b.uid",'LEFT')
     ->where($where)
     ->order($order)
     ->paginate($pageNum);
     $page = $list->render();
     $this->assign('page', $page);
     $this->assign('list', $list->toArray()['data']);
     return $this->fetch();
	}


  public function audit(){
         $param =$this->request->param();
         $CertificationBank = model('CertificationBank')->getCertificationBankInfoById($param['id'])->toArray();
         
         $user = model('Users')->getUserByUid($CertificationBank['uid']);
         $CertificationBank['username'] =$user['username'];
         $this->assign('CertificationBank',$CertificationBank);
         return $this->fetch();
  }


//通过
  public function pass(){
    $param = $this->request->param();
    if($this->request->isPost()){

        //验证
        $rule =[
          'id'=>'require|num',
        ];
        $msg= [
         'id.require' =>'ID不能为空',
         'id.num' =>'ID参数不存在',
        ];
         $error = $this->checkSubmit($param,$rule,$msg);  
       if($error){
              return error_json($error);
         }
    
        //表单数据       

          $data['status'] = 1;
          $where['id'] = $param['id'];
          $res = model('CertificationRealname')->editData($data,$where);
          return success_json('编辑成功'); 
    }

}
  //拒绝
public function refuse(){
    $param = $this->request->param();
    if($this->request->isPost()){

        //验证
        $rule =[
          'title'=>'require|chsAlpha',
          'name'=>'require',
        ];
        $msg= [
         'title.require' =>'规则标题不能为空',
         'title.chsAlpha' =>'规则标题只能是汉字或字母',
         'name.require' =>'规则名称不能为空',  
        ];
         $error = $this->checkSubmit($param,$rule,$msg);  
       if($error){
              return error_json($error);
         }
    
        //表单数据       
          $data['title'] = $param['title'];
          $data['name'] = $param['name'];
          $data['type'] = $param['type'];
          $data['condition'] = $param['condition'];
          $data['status'] = !empty($param['status'])?1:0;
          $where['id'] = $param['id'];
          $res = model('CertificationRealname')->editData($data,$where);
          return success_json('编辑成功'); 
    }   
  }
  public function del(){
      $param =$this->request->param();
     if(!$param['id']){  return error_json('请求参数错误');    }

     $res= model('CertificationBank')->delData("id",$param['id']);
       if($res){
         return success_json('删除成功');
       }else{
         return error_json($res);
       }
    }
      

}